//app.js
App({
  onLaunch: function () {
    // 展示本地存储能力
    var logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
        let ru = this.globalData.requestUrl;
        console.log("ru", ru);
        wx.request({
          url: ru + '5c77e2b3d0df7',
          data: { CODE: res.code },
          header: { version: "v3.0" },
          method: 'POST',
          dataType: 'json',
          responseType: 'text',
          success: function (res) {
            wx.setStorageSync("cmkc_user_id", res.data.data.cmkc_user_id);
          },
          fail: function (res) { },
          complete: function (res) { },
        })
      }
    })
    // 获取用户信息
    wx.getSetting({
      success: res => {
        console.log("resssss", res);
        if (res.authSetting['scope.userInfo']) {
          // 已经授权，可以直接调用 getUserInfo 获取头像昵称，不会弹框
          wx.getUserInfo({
            success: res => {
              // 可以将 res 发送给后台解码出 unionId
              this.globalData.userInfo = res.userInfo
              if (this.userInfoReadyCallback) {
                this.userInfoReadyCallback(res)
              }
            }
          })
        }
      }
    })
  },
  globalData: {
    userInfo: null,
    requestUrl: "https://api.dmxz.top/api/"
    // requestUrl: "http://api.dmxz.com:8080/api/"
  }
})